package manager;

/**
 * @author huangjm.2012, mohameds.2012, jaslin.wee.2012, huiwensong.2012, sheryl.tay.2012
 * 
 */

import java.util.ArrayList;

import manager.database.DatabaseMgr;
import manager.entitycreator.SectionCreator;
import entity.Section;

public class CartMgr {

	private DatabaseMgr dbMgr = new DatabaseMgr();
	private SectionCreator sectionCreator = new SectionCreator();

	public boolean addSectionForStudent(String courseCode, String sectionCode,
			String userId) {
		String sql = "insert into cart (cart_courseCode, cart_sectionCode, cart_userId) VALUES (?, ?, ?) ";
		int numRowsAffected = dbMgr.executeUpdate(sql, courseCode, sectionCode,
				userId);
		return numRowsAffected > 0;
	}

	
	public void deleteSectionForStudent(String courseCode, String sectionCode,
			String userId) {
		String sql = "delete from cart where cart_courseCode=? and cart_sectionCode=? and cart_userId=? ";
		dbMgr.executeUpdate(sql, courseCode, sectionCode, userId);
	}

	public void reset() {
		dbMgr.executeUpdate("delete from cart");
	}

	public ArrayList<Section> retrieveSectionsForStudent(String userId) {
		String sql = "select * from cart_with_section_course where cart_userId=?";
		return dbMgr.retrieveMultipleEntitiesForQuery(sectionCreator, sql,
				userId);
	}

}
